package com.akto.util;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;

import com.akto.dao.AccountsDao;
import com.akto.dao.context.Context;
import com.akto.dto.Account;
import com.mongodb.client.model.Filters;

import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AccountTask {
    private static final Logger logger = LoggerFactory.getLogger(AccountTask.class);
    public static final AccountTask instance = new AccountTask();

    public static final Set<Integer> inactiveAccountsSet = new HashSet(Arrays.asList(
            1705136665, 1705133177, 1705112829, 1705040462, 1705027836, 1705020271, 1705000745, 1704997839, 1704995655,
            1704995317, 1704969794, 1704954400, 1704954051, 1704938081, 1704924910, 1704909761, 1704890180, 1704868574,
            1704776019, 1704738128, 1704723880, 1704684635, 1704683492, 1704669430, 1704655494, 1704620728, 1704600315,
            1704599442, 1704495282, 1704490318, 1704414978, 1704347390, 1704328059, 1704315677, 1704307950, 1704273507,
            1704253540, 1704151015, 1704144414, 1704069512, 1704050051, 1703929694, 1703892830, 1703885959, 1703774248,
            1703726702, 1703720458, 1703704531, 1703701777, 1703698660, 1703697893, 1703646633, 1703646100, 1703637687,
            1703637658, 1703637018, 1703629125, 1703624315, 1703617157, 1703558047, 1703557960, 1703553978, 1703551763,
            1703542586, 1703530078, 1703522758, 1703228060, 1703201816, 1703201545, 1703193692, 1703185913, 1703133472,
            1703132913, 1703121174, 1703120994, 1703118554, 1703110131, 1703099409, 1703072144, 1703058239, 1703056523,
            1703053887, 1703045923, 1703039136, 1703029396, 1702990920, 1702976455, 1702970743, 1702881036, 1702873792,
            1702854379, 1702744345, 1702726288, 1702659150, 1702640517, 1702638132, 1702602883, 1702502850, 1702498132,
            1702446475, 1702444904, 1702436540, 1702435714, 1702426130, 1702389720, 1702363343, 1702347868, 1702344665,
            1702328458, 1702325580, 1702319626, 1702317265, 1702303340, 1702301600, 1702254093, 1702226352, 1702193451,
            1702193390, 1702157630, 1702085864, 1702023477, 1702020838, 1702001661, 1702000462, 1701996761, 1701985431,
            1701906740, 1701906165, 1701894229, 1701892744, 1701889487, 1701878430, 1701867926, 1701862889, 1701854683,
            1701842713, 1701831137, 1701826787, 1701817411, 1701811267, 1701809877, 1701792685, 1701760636, 1701757966,
            1701721865, 1701654172, 1701651361, 1701646540, 1701646053, 1701644183, 1701592005, 1701582661, 1701577883,
            1701570013, 1701569787, 1701538992, 1701505990, 1701416853, 1701416786, 1701416763, 1701415228, 1701414872,
            1701402887, 1701390808, 1701389863, 1701329291, 1701327172, 1701321995, 1701289591, 1701251685, 1701247004,
            1701244494, 1701241651, 1701208779, 1701207652, 1701188409, 1701177559, 1701165597, 1701145921, 1701137003,
            1701126613, 1701126302, 1701120240, 1701117446, 1701109976, 1701109043, 1701097183, 1701081803, 1701064712,
            1701061544, 1701042327, 1701041213, 1701033739, 1701033605, 1701024609, 1701021538, 1701018082, 1701004993,
            1700996055, 1700979890, 1700978295, 1700964512, 1700923346, 1700910093, 1700891225, 1700880230, 1700863458,
            1700787326, 1700787018, 1700780249, 1700779836, 1700773860, 1700770234, 1700761005, 1700760268, 1700757157,
            1700727504, 1700722903, 1700716457, 1700715361, 1700712891, 1700709234, 1700708510, 1700707790, 1700698881,
            1700689356, 1700683736, 1700657005, 1700644216, 1700631354, 1700624856, 1700621698, 1700617373, 1700607968,
            1700601626, 1700597392, 1700594613, 1700591679, 1700587672, 1700573377, 1700571811, 1700551986, 1700541138,
            1700519946, 1700492038, 1700482634, 1700472954, 1700457619, 1700455610, 1700449227, 1700442129, 1700438275,
            1700437102, 1700437044, 1700433681, 1700430313, 1700422310, 1700421987, 1700394413, 1700376941, 1700345326,
            1700313461, 1700306097, 1700294822, 1700262205, 1700258470, 1700250498, 1700247456, 1700242100, 1700238537,
            1700227752, 1700191003, 1700189423, 1700178127, 1700168034, 1700162013, 1700161330, 1700139695, 1700123775,
            1700123335, 1700121054, 1700117864, 1700116956, 1700112256, 1700111915, 1700085340, 1700080403, 1700076786,
            1700070659, 1700062187, 1700031937, 1700022623, 1700004714, 1699994696, 1699994696, 1699981206, 1699972132,
            1699967709, 1699958958, 1699949805, 1699946463, 1699944154, 1699938165, 1699930961, 1699925779, 1699908233,
            1699906129, 1699904244, 1699894512, 1699892207, 1699864671, 1699859978, 1699857306, 1699850108, 1699842015,
            1699829004, 1699828511, 1699825878, 1699812443, 1699805656, 1699798258, 1699793900, 1699769511, 1699727389,
            1699694369, 1699686528, 1699651128, 1699641910, 1699626391, 1699590504, 1699575421, 1699565843, 1699560746,
            1699555765, 1699526680, 1699523573, 1699511169, 1699507745, 1699498247, 1699494362, 1699493725, 1699490590,
            1699487208, 1699482960, 1699479733, 1699447258, 1699441622, 1699434784, 1699426186, 1699410179, 1699407437,
            1699400655, 1699392411, 1699386823, 1699381957, 1699380136, 1699378193, 1699377706, 1699376768, 1699371891,
            1699345772, 1699329597, 1699323666, 1699314362, 1699311043, 1699299386, 1699291798, 1699290989, 1699288116,
            1699250348, 1699243573, 1699241134, 1699241005, 1699219427, 1699211128, 1699206684, 1699206684, 1699206684,
            1699199732, 1699187870, 1699163359, 1699161628, 1699158086, 1699157996, 1699148653, 1699132448, 1699079326,
            1699074032, 1699059034, 1699035234, 1699028893, 1699011144, 1699007019, 1698993194, 1698986578, 1698978994,
            1698967194, 1698950996, 1698928692, 1698914917, 1698907673, 1698906135, 1698881726, 1698861234, 1698860789,
            1698857888, 1698835097, 1698812375, 1698805091, 1698798273, 1698792873, 1698791354, 1698779698, 1698777185,
            1698775756, 1698766098, 1698748710, 1698732777, 1698725205, 1698724344, 1698710974, 1698701956, 1698701944,
            1698699626, 1698686389, 1698666179, 1698663332, 1698651233, 1698646837, 1698644740, 1698636421, 1698634233,
            1698629321, 1698626493, 1698622537, 1698614571, 1698610923, 1698609513, 1698583105, 1698548585, 1698546368,
            1698506660, 1698495163, 1698494155, 1698475207, 1698473448, 1698471835, 1698469475, 1698465619, 1698437696,
            1698415778, 1698415232, 1698414658, 1698414451, 1698414312, 1698414272, 1698414223, 1698414161, 1698414139,
            1698414107, 1698414102, 1698414095, 1698393685, 1698386116, 1698384069, 1698376233, 1698349402, 1698348803,
            1698346831, 1698346241, 1698331679, 1698331576, 1698331575, 1698331471, 1698331466, 1698331459, 1698331298,
            1698331294, 1698331293, 1698331290, 1698331288, 1698331284, 1698331255, 1698331252, 1698331245, 1698331200,
            1698331199, 1698331190, 1698331187, 1698330862, 1698318359, 1698317869, 1698311980, 1698295180, 1698291850,
            1698270429, 1698268935, 1698265595, 1698264867, 1698263234, 1698258595, 1698254435, 1698249880, 1698233151,
            1698213320, 1698203367, 1698203170, 1698201149, 1698199747, 1698197541, 1698191670, 1698191420, 1698185644,
            1698177398, 1698166879, 1698166367, 1698161367, 1698161358, 1698161348, 1698138651, 1698133616, 1698129290,
            1698127666, 1698127569, 1698124715, 1698121895, 1698116613, 1698114809, 1698110998, 1698098028, 1698091924,
            1698078612, 1698075008, 1698069312, 1698046260, 1698038219, 1698022131, 1698021596, 1698016044, 1697974271,
            1697946609, 1697938109, 1697861221, 1697855375, 1697781565, 1697781302, 1697768883, 1697765244, 1697760716,
            1697747408, 1697746135, 1697744966, 1697731879, 1697707124, 1697706615, 1697702794, 1697700188, 1697695877,
            1697694713, 1697676061, 1697672499, 1697669752, 1697668351, 1697668011, 1697648225, 1697594460, 1697590453,
            1697583332, 1697579719, 1697576608, 1697576515, 1697571544, 1697571335, 1697570878, 1697569966, 1697560082,
            1697495520, 1697490754, 1697476008, 1697449386, 1697438807, 1697438007, 1697432351, 1697429556, 1697419170,
            1697408247, 1697401113, 1697393552, 1697389184, 1697377451, 1697360398, 1697355890, 1697349625, 1697331690,
            1697298753, 1697275304, 1697257441, 1697247018, 1697235255, 1697233152, 1697227157, 1697225026, 1697211102,
            1697210341, 1697179027, 1697174999, 1697169443, 1697163447, 1697147431, 1697146340, 1697136896, 1697136623,
            1697123813, 1697123660, 1697099439, 1697094377, 1697088224, 1697085096, 1697081727, 1697078255, 1697062698,
            1697061341, 1697059307, 1697052656, 1697048134, 1697047292, 1697012902, 1697012692, 1696996897, 1696987378,
            1696984971, 1696983019, 1696979677, 1696965431, 1696963328, 1696948962, 1696924647, 1696904849, 1696898538,
            1696888352, 1696881156, 1696873301, 1696865979, 1696863833, 1696841102, 1696822037, 1696821345, 1696820352,
            1696819801, 1696814300, 1696801684, 1696798844, 1696787011, 1696743785, 1696740306, 1696731192, 1696659979,
            1696625410, 1696573279, 1696568503, 1696523610, 1696521592, 1696489601, 1696481604, 1696481511, 1696468375,
            1696461151, 1696449708, 1696448713, 1696404504, 1696394389, 1696391279, 1696384160, 1696380941, 1696363846,
            1696362737, 1696355044, 1696351403, 1696321249, 1696310164, 1696309975, 1696303949, 1696287251, 1696283367,
            1696246838, 1696227309, 1696223973, 1696223646, 1696214245, 1696195770, 1696191918, 1696178518, 1696172131,
            1696163591, 1696126615, 1696097888, 1696064529, 1696046375, 1696013630, 1695996945, 1695977549, 1695965048,
            1695955884, 1695949566, 1695945163, 1695942313, 1695934297, 1695906165, 1695901847, 1695885340, 1695877265,
            1695857314, 1695820032, 1695809881, 1695791767, 1695784040, 1695779904, 1695779302, 1695778515, 1695773788,
            1695719884, 1695718819, 1695715381, 1695714552, 1695711777, 1695704479, 1695691204, 1695690439, 1695673229,
            1695671499, 1695666505, 1695664511, 1695663354, 1695661992, 1695613281, 1695611606, 1695609208, 1695609202,
            1695608028, 1695599819, 1695591240, 1695581777, 1695496189, 1695494032, 1695452963, 1695451102, 1695447097,
            1695437787, 1695412803, 1695378919, 1695356176, 1695349345, 1695346709, 1695337133, 1695334457, 1695319050,
            1695287162, 1695270589, 1695268264, 1695268012, 1695253515, 1695242256, 1695235093, 1695192689, 1695188457,
            1695184753, 1695182048, 1695169790, 1695160251, 1695151577, 1695149808, 1695141251, 1695128492, 1695124344,
            1695117408, 1695106477, 1695099963, 1695098823, 1695098804, 1695094242, 1695089424, 1695087050, 1695073684,
            1695070985, 1695052944, 1695018599, 1695012312, 1694992054, 1694991906, 1694990485, 1694986616, 1694969528,
            1694939027, 1694928463, 1694918846, 1694897365, 1694895391, 1694878769, 1694849162, 1694835484, 1694808742,
            1694804908, 1694761720, 1694759602, 1694759290, 1694744061, 1694742924, 1694735788, 1694725167, 1694724088,
            1694723643, 1694721402, 1694718920, 1694681418, 1694653991, 1694648033, 1694642947, 1694620663, 1694617233,
            1694611074, 1694592644, 1694582347, 1694579246, 1694575742, 1694570759, 1694566217, 1694555949, 1694553948,
            1694548410, 1694530343, 1694479260, 1694478778, 1694469694, 1694467033, 1694442409, 1694436471, 1694420592,
            1694417493, 1694409167, 1694408759, 1694405600, 1694404688, 1694404381, 1694397153, 1694387548, 1694380695,
            1694374585, 1694366996, 1694362523, 1694327710, 1694274512, 1694274281, 1694273588, 1694229649, 1694215131,
            1694207434, 1694161819, 1694149865, 1694137376, 1694134275, 1694116810, 1694102773, 1694050686, 1694050361,
            1694050128, 1694047973, 1694046433, 1694038403, 1694025775, 1694015888, 1693998783, 1693992941, 1693975788,
            1693973471, 1693965351, 1693961827, 1693958956, 1693952769, 1693948644, 1693939881, 1693939269, 1693936923,
            1693930674, 1693929926, 1693927626, 1693926459, 1693920007, 1693894859, 1693885310, 1693879407, 1693878286,
            1693864558, 1693864209, 1693863428, 1693848193, 1693847454, 1693845303, 1693836979, 1693828325, 1693799329,
            1693798197, 1693783419, 1693780359, 1693779759, 1693769199, 1693767926, 1693751740, 1693714714, 1693698961,
            1693669229, 1693652719, 1693648859, 1693632503, 1693594787, 1693580236, 1693561147, 1693548857, 1693529339,
            1693528155, 1693512739, 1693510631, 1693506187, 1693503854, 1693484929, 1693449506, 1693442240, 1693421754,
            1693413862, 1693413622, 1693395059, 1693373095, 1693358710, 1693356111, 1693340718, 1693337748, 1693332485,
            1693327541, 1693320774, 1693320359, 1693299824, 1693298701, 1693293172, 1693288165, 1693285723, 1693271598,
            1693255350, 1693254230, 1693247915, 1693247615, 1693247518, 1693246919, 1693242650, 1693241353, 1693216589,
            1693215848, 1693204064, 1693203820, 1693195294, 1693194903, 1693185722, 1693179617, 1693168678, 1693168180,
            1693166929, 1693164443, 1693156618, 1693088310, 1693082763, 1693074476, 1693021017, 1693003934, 1693003857,
            1692991970, 1692951204, 1692948762, 1692945283, 1692939110, 1692937905, 1692937282, 1692934339, 1692932695,
            1692932118, 1692928130, 1692912626, 1692911103, 1692908153, 1692907118, 1692906485, 1692905618, 1692903873,
            1692903716, 1692903708, 1692895563, 1692893099, 1692891052, 1692888335, 1692888253, 1692888064, 1692887726,
            1692887709, 1692887537, 1692887302, 1692887191, 1692887084, 1692887072, 1692887050, 1692887048, 1692887047,
            1692887031, 1692886956, 1692886952, 1692886939, 1692884719, 1692879591, 1692859094, 1692852046, 1692850178,
            1692835567, 1692835078, 1692833810, 1692828979, 1692825826, 1692817771, 1692773620, 1692772659, 1692758663,
            1692752799, 1692752370, 1692752060, 1692749217, 1692745324, 1692735935, 1692724759, 1692721882, 1692714691,
            1692705938, 1692705035, 1692694986, 1692684831, 1692683631, 1692682709, 1692658409, 1692656847, 1692656462,
            1692653749, 1692648365, 1692646346, 1692631224, 1692622918, 1692612136, 1692611175, 1692605844, 1692578924,
            1692573351, 1692559361, 1692556619, 1692552231, 1692549277, 1692536237, 1692534245, 1692533146, 1692525777,
            1692514447, 1692507122, 1692491984, 1692490152, 1692431814, 1692421277, 1692414456, 1692397395, 1692382849,
            1692350231, 1692342054, 1692340826, 1692335583, 1692329532, 1692320480, 1692310924, 1692298009, 1692261428,
            1692258405, 1692249490, 1692245328, 1692242109, 1692237661, 1692237041, 1692223439, 1692223381, 1692221066,
            1692214863, 1692211903, 1692207804, 1692207649, 1692205196, 1692196239, 1692195914, 1692195407, 1692195368,
            1692194911, 1692194731, 1692194630, 1692194231, 1692194213, 1692194183, 1692194167, 1692194089, 1692194075,
            1692194036, 1692193934, 1692193855, 1692193825, 1692193811, 1692193782, 1692193762, 1692193711, 1692193706,
            1692193689, 1692193679, 1692193671, 1692193657, 1692193649, 1692193639, 1692193626, 1692193521, 1692175521,
            1692169745, 1692161290, 1692159828, 1692156357, 1692154212, 1692153911, 1692140846, 1692136053, 1692130764,
            1692110264, 1692091533, 1692075381, 1692071488, 1692068126, 1692065021, 1692060832, 1692055862, 1692054718,
            1692052029, 1692047956, 1692040951, 1692009663, 1691989718, 1691984595, 1691982358, 1691981081, 1691976988,
            1691969006, 1691957233, 1691949404, 1691916150, 1691891526, 1691825122, 1691821983, 1691803911, 1691734935,
            1691721051, 1691708849, 1691708637, 1691701648, 1691692570, 1691686120, 1691683113, 1691682129, 1691675338,
            1691675247, 1691633721, 1691633381, 1691630933, 1691626149, 1691620105, 1691615927, 1691615807, 1691614222,
            1691612217, 1691592547, 1691592224, 1691571404, 1691566085, 1691559946, 1691557372, 1691553634, 1691543590,
            1691542898, 1691540229, 1691536266, 1691528429, 1691525663, 1691525121, 1691510592, 1691504294, 1691500714,
            1691467974, 1691462785, 1691460675, 1691457785, 1691446791, 1691443904, 1691435648, 1691434785, 1691427402,
            1691416299, 1691406413, 1691369873, 1691369475, 1691368028, 1691365318, 1691358278, 1691356538, 1691354805,
            1691345392, 1691342266, 1691339865, 1691311684, 1691310943, 1691306873, 1691283933, 1691240420, 1691218976,
            1691218715, 1691202831, 1691202646, 1691199544, 1691188920, 1691185248, 1691171585, 1691150888, 1691144731,
            1691136117, 1691121523, 1691115149, 1691113168, 1691110878, 1691102380, 1691094369, 1691092919, 1691092264,
            1691047843, 1691038633, 1691034329, 1691027652, 1691024024, 1691014255, 1691011837, 1691009785, 1691001256,
            1690994657, 1690992708, 1690984224, 1690977792, 1690974710, 1690971838, 1690962670, 1690957577, 1690954535,
            1690945097, 1690942773, 1690942760, 1690942543, 1690942162, 1690941946, 1690941701, 1690941361, 1690940911,
            1690937231, 1690936946, 1690934524, 1690933734, 1690919802, 1690918044, 1690904606, 1690903790, 1690898567,
            1690892023, 1690889926, 1690885161, 1690874270, 1690853672, 1690852086, 1690849366, 1690848264, 1690848241,
            1690780188, 1690768986, 1690759941, 1690747727, 1690746260, 1690738373, 1690721411, 1690672691, 1690618945,
            1690617075, 1690613057, 1690586362, 1690570731, 1690545062, 1690540341, 1690522117, 1690518875, 1690512711,
            1690504838, 1690504753, 1690500413, 1690491860, 1690489999, 1690488081, 1690481662, 1690473928, 1690472694,
            1690430301, 1690423553, 1690417910, 1690417690, 1690399864, 1690389597, 1690382602, 1690348834, 1690341118,
            1690339333, 1690335235, 1690334765, 1690326067, 1690323727, 1690320704, 1690317287, 1690315568, 1690308666,
            1690293573, 1690289103, 1690269559, 1690262307, 1690260379, 1690257207, 1690257002, 1690252401, 1690250942,
            1690244397, 1690239456, 1690235207, 1690231684, 1690222721, 1690204012, 1690192747, 1690191326, 1690181532,
            1690176268, 1690162182, 1690161503, 1690160897, 1690133953, 1690109728, 1690105645, 1690090506, 1690087083,
            1690078846, 1690076003, 1690022646, 1690021956, 1690004941, 1690003811, 1689998039, 1689992489, 1689985826,
            1689985308, 1689984572, 1689982750, 1689970903, 1689967651, 1689954567, 1689940448, 1689927526, 1689908367,
            1689901103, 1689895634, 1689892179, 1689890267, 1689888960, 1689870569, 1689858156, 1689846663, 1689828180,
            1689824803, 1689824443, 1689824182, 1689823566, 1689820992, 1689820721, 1689818518, 1689799686, 1689792410,
            1689580604, 1689278954, 1688759374, 1688681856, 1688200388, 1687834607, 1687551721, 1687548436, 1687454408,
            1687392386, 1686969677, 1686783539, 1686681829, 1686529350, 1685916769, 1685916624, 1685553847, 1685126021,
            1684677854, 1684461486, 1684372965, 1684270015, 1684258957, 1684245879, 1684203303, 1683989980, 1683989750,
            1683956043, 1683762837, 1683336274, 1683160090, 1683145792, 1682555919, 1682375754, 1681946236, 1681842817,
            1681832674, 1681706406, 1681575942, 1681575917, 1681552002, 1681395356, 1681377018, 1681277253, 1681265678,
            1681263260, 1681220474, 1681060034, 1680830634, 1680718740, 1680569572, 1680557277, 1680471209, 1680328370,
            1680328216, 1680256250, 1680213571, 1680200091, 1680157433, 1679956761, 1679956696, 1679927029, 1679761108,
            1679752143, 1679687624, 1679631939, 1679605272, 1679542420, 1679514953, 1679453410, 1679276126, 1679204184,
            1679021058, 1678968469, 1678858348, 1678839507, 1678503672, 1678220118, 1678110973, 1677769340, 1677769153,
            1677550213, 1677550034, 1677451810, 1677442109, 1677234608, 1677184342, 1677109176, 1676858279, 1676683131,
            1676576335, 1676426318, 1676333101, 1676226859, 1676007623, 1675888705, 1675623399, 1675622133, 1675224458,
            1675207041, 1675206947, 1675183826, 1675156242, 1674973630, 1674765989, 1674752681, 1674694746, 1674532957,
            1674161810, 1673809166, 1673720021, 1673660542, 1673660523, 1673603452, 1673366238, 1672644047, 1672627473,
            1672625609, 1672623084, 1672367611, 1672257456, 1672217884, 1671835776, 1671824567, 1671501851, 1671424128,
            1671400457, 1671399899, 1671396142, 1671264993, 1671092519, 1670611494, 1670611254, 1670458005, 1670457957,
            1670308230, 1670307654, 1670289631, 1670287521, 1670287223, 1670286570, 1670286570, 1670285153, 1670281118,
            1670267989, 1670224891, 1669890901, 1669849881, 1669849881, 1669848064, 1669847346, 1669846292, 1669696185,
            1669249849, 1669249849, 1669249536, 1668886444, 1668713793, 1668708767, 1668643781, 1668643781, 1668602958,
            1668602935, 1668538738, 1668401835, 1667867111, 1667852703, 1667851063, 1667590105, 1667540313, 1667489632,
            1667464609, 1667450477, 1667450448, 1667357446, 1666812451, 1666551544, 1666296009, 1666293928, 1665621595,
            1665621595, 1665621595, 1665026454, 1665022305, 1665022305, 1663003516, 1663002958, 1663002941, 1662756520,
            1662681374, 1662680009, 1662667201, 1662664207, 1662663641, 1662656702, 1662636440, 1662504770
    ));



    public void executeTask(Consumer<Account> consumeAccount, String taskName) {

        Bson activeFilter = Filters.or(
                Filters.exists(Account.INACTIVE_STR, false),
                Filters.eq(Account.INACTIVE_STR, false)
        );

        List<Account> activeAccounts = AccountsDao.instance.findAll(activeFilter);
        for(Account account: activeAccounts) {
            if (inactiveAccountsSet.contains(account.getId())) {
                continue;
            }
            try {
                Context.accountId.set(account.getId());
                consumeAccount.accept(account);
            } catch (Exception e) {
                String msgString = String.format("Error in executing task %s for account %d", taskName, account.getId());
                logger.error(msgString, e);
            }
        }

    }

    public void executeTaskHybridAccounts(Consumer<Account> consumeAccount, String taskName) {

        Bson activeFilter = Filters.or(
                Filters.exists(Account.INACTIVE_STR, false),
                Filters.eq(Account.INACTIVE_STR, false)
        );

        Bson accountFilter = Filters.eq(Account.HYBRID_SAAS_ACCOUNT, true);

        Bson combinedFilter = Filters.and(activeFilter, accountFilter);

        List<Account> activeAccounts = AccountsDao.instance.findAll(combinedFilter);
        logger.info("executeTaskHybridAccounts: accounts length" + activeAccounts.size());
        for(Account account: activeAccounts) {
            try {
                Context.accountId.set(account.getId());
                consumeAccount.accept(account);
            } catch (Exception e) {
                String msgString = String.format("Error in executing task %s for account %d", taskName, account.getId());
                logger.error(msgString, e);
            }
        }

    }

    public void executeTaskForNonHybridAccounts(Consumer<Account> consumeAccount, String taskName) {

        Bson activeFilter = Filters.or(
                Filters.exists(Account.INACTIVE_STR, false),
                Filters.eq(Account.INACTIVE_STR, false)
        );

        Bson nonHybridAccountsFilter = Filters.or(
            Filters.exists(Account.HYBRID_TESTING_ENABLED, false),
            Filters.eq(Account.HYBRID_TESTING_ENABLED, false)
        );

        List<Account> activeAccounts = AccountsDao.instance.findAll(Filters.and(activeFilter, nonHybridAccountsFilter));
        for(Account account: activeAccounts) {
            if (inactiveAccountsSet.contains(account.getId())) {
                continue;
            }
            try {
                Context.accountId.set(account.getId());
                consumeAccount.accept(account);
            } catch (Exception e) {
                String msgString = String.format("Error in executing task %s for account %d", taskName, account.getId());
                logger.error(msgString, e);
            }
        }
    }
}
